package demo3;

import java.util.*;

public class Main {

    public static void main1(String[] args) {
         Scanner in = new Scanner(System.in);
         char[] a = in.next().toCharArray();
         char[] b = in.next().toCharArray();
         int m = a.length, n = b.length;

         int ret = m;
         for(int i = 0; i <= n - m; i++){
             int tmp = 0;
             for(int j = 0; j < m; j++){
                 if(a[i] != b[i + j]){
                     tmp++;
                 }
             }
             ret = Math.min(ret, tmp);
         }
        System.out.println(ret);
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        int max = 0;
        for(int i = 0; i< n; i++){
            arr[i] = in.nextInt();
            max = Math.max(max, arr[i]);
        }

        boolean flag = true;
        for(int i = 0; i < n; i++){
            if(max % arr[i] != 0){
                flag = false;
                break;
            }
            int x = max / arr[i];
            if((x & (x - 1)) != 0){
                flag = false;
                break;
            }
        }
        if(flag){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int v = in.nextInt(), n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = in.nextInt();
        }

        int[][] dp = new int[n + 1][v + 1];
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= v; j++){
                dp[i][j] = dp[i - 1][j];
                if(j >= arr[i]){
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - arr[i]] + arr[i]);
                }
            }
        }
        System.out.println(v - dp[n][v]);
    }
}
